﻿/*
 * Created by SharpDevelop.
 * User: Dror B. Helper
 * Date: 15/09/2009
 * Time: 22:31
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using StackOverflowNotifier2;
using System;
using System.Collections.Generic;
using NUnit.Framework;

namespace StackOverflowNotifier2UnitTests
{
	[TestFixture]
	public class ParserTests
	{
		const string flair1 = @"
<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">
<html xmlns=""http://www.w3.org/1999/xhtml\"">
<head>
    <meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"" />   
    
            <link rel=""stylesheet"" href=""http://sstatic.net/so/flair-Default.StackOverflow.css"" />
            
</head>
<body>
    <div class=""valuable-flair"">
    <div class=""gravatar"">
        <a title=""See my profile on Stack Overflow"" target=""_blank"" href=""http://stackoverflow.com/users/11361/dror-helper""><img src=""http://www.gravatar.com/avatar/db8b562e21f8f67bd924c3d6bcc60f4c?s=50&amp;d=identicon&amp;r=PG"" height=""50"" width=""50"" alt=""""></a>
    </div>
    <div class=""userInfo"">
        <span class=""username""><img src=""http://sstatic.net/so/favicon.ico"" /><a href=""http://stackoverflow.com/users/11361/dror-helper"" target=""_blank"">Dror Helper</a></span>
        <br />
        <span class=""reputation-score"" title=""reputation score"">2,923</span>
        <br />
        <span title=""4 silver badges""><span class=""badge2"">&#9679;</span><span class=""badgecount"">4</span></span><span title=""20 bronze badges""><span class=""badge3"">&#9679;</span><span class=""badgecount"">20</span></span>
    </div>
</div>       
</body>
</html>";
		
		const string flair2 = @"
		<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">
<html xmlns=""http://www.w3.org/1999/xhtml"">
<head>
    <meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"" />   
    
            <link rel=""stylesheet"" href=""http://sstatic.net/so/flair-Default.StackOverflow.css"" />
            
</head>
<body>
    <div class=""valuable-flair"">
    <div class=""gravatar"">
        <a title=""See my profile on Stack Overflow"" target=""_blank"" href=""http://stackoverflow.com/users/22656/jon-skeet""><img src=""http://www.gravatar.com/avatar/6d8ebb117e8d83d74ea95fbdd0f87e13?s=50&amp;d=identicon&amp;r=PG"" height=""50"" width=""50"" alt=""></a>
    </div>

    <div class=""userInfo"">
        <span class=""username""><img src=""http://sstatic.net/so/favicon.ico"" /><a href=""http://stackoverflow.com/users/22656/jon-skeet"" target=""_blank"">Jon Skeet</a></span>
        <br />
        <span class=""reputation-score"" title=""reputation score"">97,311</span>
        <br />
        <span title=""16 gold badges""><span class=""badge1"">&#9679;</span><span class=""badgecount"">16</span></span><span title=""337 silver badges""><span class=""badge2"">&#9679;</span><span class=""badgecount"">337</span></span><span title=""748 bronze badges""><span class=""badge3"">&#9679;</span><span class=""badgecount"">748</span></span>

    </div>
</div>       
</body>
</html>";
		
		[Test]
		public void ParseName_ParseSOFlair_ReturnCorrectUserName()
		{
			var parser = new Parser2();
			var name = parser.ParseName(flair1);
			
			Assert.That(name, Is.EqualTo("Dror Helper"));
		}
		
		[Test]
		public void ParseReputation_ParseSOFlair_ReturnCorrectReputationScore()
		{		
			var parser = new Parser2();
			var reputation = parser.ParseReputation(flair1);
			
			Assert.That(reputation, Is.EqualTo(2923));
		}
		
		[Test]
		public void ParseBandgeCountSilver_ParseSOFlair_ReturnCorrectBandgeCount()
		{		
			var parser = new Parser2();
			var badgeCount = parser.ParseBandgeCount(flair1, Parser2.BadgeType.Silver);
			
			Assert.That(badgeCount, Is.EqualTo(4));
		}
		
		[Test]
		public void ParseBandgeCountBronze_ParseSOFlair_ReturnCorrectBandgeCount()
		{		
			var parser = new Parser2();
			var badgeCount = parser.ParseBandgeCount(flair1, Parser2.BadgeType.Bronze);
			
			Assert.That(badgeCount, Is.EqualTo(20));
		}
		
		[Test]
		public void ParseBandgeCountGold_ParseSOFlairGoldBadgeDoesNotExist_ReturnCorrectBandgeCount()
		{		
			var parser = new Parser2();
			var badgeCount = parser.ParseBandgeCount(flair1, Parser2.BadgeType.Gold);
			
			Assert.That(badgeCount, Is.EqualTo(0));
		}
		
		[Test]
		public void ParseBandgeCountGold_ParseSOFlair_ReturnCorrectBandgeCount()
		{		
			var parser = new Parser2();
			var badgeCount = parser.ParseBandgeCount(flair2, Parser2.BadgeType.Gold);
			
			Assert.That(badgeCount, Is.EqualTo(16));
		}
	}
}